package com.tjetc.view;

import com.tjetc.domain.*;
import com.tjetc.service.*;
import com.tjetc.utils.App;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class IndexView {
    private AdminService adminService=new AdminService();
    private BossService bossService=new BossService();
    private CoachService coachService=new CoachService();
    private FanService fanService=new FanService();
    private TeamService teamService=new TeamService();
    private PlayerService playerService=new PlayerService();
    private  GameService gameService= new GameService();
    private FeedbackService feedbackService =new FeedbackService();
    private Coach coach=new Coach();
    private Boss boss=new Boss();
    private PlayerScoreService playerScoreService=new PlayerScoreService();
    private TeamScoreService teamScoreService=new TeamScoreService();
    public void start() {
        System.out.println("欢迎使用篮球俱乐部管理系统");
        Person person = log();
        String personClassName = person.getClass().getSimpleName();
        switch (personClassName){
            case "Admin":
                Adminshow();
                break;
            case "Boss":
                Bossshow();
                break;
            case "Coach":
                Coachshow();
                break;
            case "Fan":
                Fanshow();
                break;
            default:
                break;
        }
    }

    private void Fanshow() {
        System.out.println("1.查询赛事信息");
        System.out.println("2.查询球队信息");
        System.out.println("3.查询球员信息");
        System.out.println("4.查询球队得分");
        System.out.println("5.查询球员得分");
        System.out.println("6.给球员点赞");
        System.out.println("7.反馈信息");
        System.out.println("8.登出");
        switch (App.scanner.nextInt()){
            case 1:
                showGame();
                Fanshow();
            case 2:
                showTeam();
                Fanshow();
            case 3:
                findPlayer();
                Fanshow();
            case 4:
                findTeamScore();
                Fanshow();
            case 5:
                findPlayerScore();
                Fanshow();
            case 6:
                playerLikes();
                Fanshow();
            case 7:
                addFeedback();
                Fanshow();
            case 8:
                start();
                break;
            default:
                break;
        }
    }

    private void findTeamScore() {
        System.out.println("球队得分表");
        List<TeamScore> teamScores=teamScoreService.findTeamScore();
        if (teamScores!=null){
            for (TeamScore teamScore : teamScores) {
                //System.out.println(teamScore.getId()+"\t"+ teamScore.getTeamId()+"\t"+teamScore.getScore());
                if (coachService.findTeamByTeamId(teamScore.getTeamId()) != null) {
                    System.out.println("球队:" + coachService.findTeamByTeamId(teamScore.getTeamId()).getName());
                    System.out.println("球队得分:" + teamScore.getScore());
                }
            }
        }else {
            System.out.println("没有球队得分");
        }
    }

    private void findPlayerScore() {
        System.out.println("球员得分表");
        List<PlayerScore> playerScores=playerScoreService.findPlayerScore();
        if (playerScores!=null){
            for (PlayerScore playerScore : playerScores) {
                //System.out.println(playerScore.getId()+"\t"+playerScore.getPlayerId()+"\t"+playerScore.getScore()+"\t"+playerScore.getGameId());
                if (playerService.findByPlayerId(playerScore.getPlayerId())!=null && coachService.findTeamByTeamId(coachService.findGameById(playerScore.getGameId()).getHomeTeamId())!=null &&coachService.findTeamByTeamId(coachService.findGameById(playerScore.getGameId()).getAwayTeamId())!=null)
                System.out.println ("球员名字:"+playerService.findByPlayerId(playerScore.getPlayerId()).getName());
                System.out.println("得分" + playerScore.getScore());
                System.out.println( "主队:"+coachService.findTeamByTeamId(coachService.findGameById(playerScore.getGameId()).getHomeTeamId()).getName());
                System.out.println( "客队:"+coachService.findTeamByTeamId(coachService.findGameById(playerScore.getGameId()).getAwayTeamId()).getName());
            }
        }else {
            System.out.println("没有球员得分");
        }
    }

    private void findPlayer() {
        System.out.println("球员列表");
        List<Player> players=playerService. findPlayer();
        if (players!=null){
            for (Player player : players) {
               // System.out.println(player.getId()+player.getName()+ player.getAge()+ player.getHeight()+ player.getWeight()+ player.getPosition()+ player.getTeamId()+ player.getSalary()+ player.getLikes());
                System.out.println("球员名字:"+playerService.findByPlayerId(player.getId()).getName());
                System.out.println("年龄:" + playerService.findByPlayerId(player.getId()).getAge());
                System.out.println("身高:" + playerService.findByPlayerId(player.getId()).getHeight());
                System.out.println("体重" + playerService.findByPlayerId(player.getId()).getWeight());
                System.out.println("站位" + playerService.findByPlayerId(player.getId()).getPosition());
                System.out.println("球队:" + coachService.findTeamByTeamId(playerService.findByPlayerId(player.getId()).getTeamId()));
                System.out.println("薪水:" + playerService.findByPlayerId(player.getId()).getSalary()+"元");
                System.out.println("点赞数:" + playerService.findByPlayerId(player.getId()).getLikes());
            }
        }else {
            System.out.println("没有球员");
        }

    }

    private void Coachshow() {
        System.out.println("1.管理球员");
        System.out.println("2.赛程登记");
        System.out.println("3.球队成绩分析");
        System.out.println("4.球员成绩分析");
        System.out.println("5.训练计划管理");
        System.out.println("6.训练项目管理");
        System.out.println("7.装备管理");
        System.out.println("0.登出");
        System.out.println("请输入操作:");
        switch (App.scanner.nextInt()){
            case 1:
                System.out.println("1.添加球员");
                System.out.println("2.删除球员");
                System.out.println("3.球员列表");
                System.out.println("4.我队球员");
                System.out.println("0.返回");
                System.out.println("请输入操作:");
                switch (App.scanner.nextInt()){
                    case 1:
                        addPlayers();
                        break;
                    case 2:
                        delPlayer();
                        break;
                    case 3:
                        showAllPlayer();
                        break;
                    case 4:
                        showPlayer();
                        break;
                    case 0:
                        Coachshow();
                        break;
                    default:
                        break;
                }
                break;
            case 2:
                showGameDeg();
                break;
            case 3:
                Teamanalysis();
                break;
            case 4:
                Playeranalysis();
                break;
            case 5:
                trainingPlan();
                break;
            case 6:
                plansteting();
                break;
            case 7:
                equipPlan();
                break;
            case 0:
                start();
                break;
            default:
                break;
        }
    }

    private void plansteting() {
        System.out.println("1.添加训练项目");
        System.out.println("2.修改训练项目");
        System.out.println("3.删除训练项目");
        System.out.println("4.训练项目列表");
        System.out.println("0.返回");
        System.out.println("请输入要操作的编号");
        switch (App.scanner.nextInt()){
            case 1:
                addDetail();
                plansteting();
                break;
            case 2:
                updataDetail();
                plansteting();
                break;
            case 3:
                delDetail();
                plansteting();
                break;
            case 4:
                showDetail();
                plansteting();
                break;
            case 0:
                Coachshow();
                break;
            default:
                break;
        }
    }

    private void showDetail() {
        coachService.showDetail();
    }

    private void delDetail() {
        while (true) {
            System.out.println("请输入要删除的训练项目的名称");
            String name=App.scanner.next();
            List<Detail> details;
            details=coachService.findDetailByname(name);
            if (details==null){
                System.out.println("不存在该项目,请重新输入项目名称");
            }else {
                for (Detail detail : details) {
                    System.out.println("项目名称:"+detail.getItem());
                    System.out.println("项目时间:"+detail.getTime()+"点");
                }
            }
            System.out.println("请输入要删除的项目时间");
            int time=App.scanner.nextInt();
            boolean b=coachService.delDetail(name,time);
            System.out.println(b ? "删除成功" : "删除失败");
            System.out.println("是否继续删除");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }

    private void updataDetail() {
        while (true) {
            String s;
            int time;
            int id;
            while (true) {
                System.out.println("请输入训练项目名称");
                s = App.scanner.next();
                System.out.println("请输入训练时间");
                time=App.scanner.nextInt();
                Detail detail=coachService.findDetail(s,time);
                if (detail==null){
                    System.out.println("训练项目不存在,请重新输入");
                }else {
                    id= detail.getId();
                    break;
                }
            }
            System.out.println("请输入修改后的项目名称");
            s = App.scanner.next();
            while (true) {
                System.out.println("请输入修改后训练时间 (10-20)");
                time=App.scanner.nextInt();
                if (time<10||time>20){
                    System.out.println("输入错误请重新输入");
                }else {
                    break;
                }
            }
            boolean b=coachService.updateDeatail(s,time,id);
            System.out.println(b ? "修改成功" : "修改失败");
            System.out.println("是否继续修改(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }

    private void addDetail() {
        while (true) {
            System.out.println("请输入训练项目名称");
            String s = App.scanner.next();
            System.out.println("请输入训练时间");
            int time=App.scanner.nextInt();
            boolean b = coachService.addDetail(s,time);
            System.out.println(b ? "添加成功" : "添加失败");
            System.out.println("是否继续添加(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }

    private void equipPlan() {
        System.out.println("1.添加装备");
        System.out.println("2.修改装备");
        System.out.println("3.删除装备");
        System.out.println("4.查看装备列表");
        System.out.println("0.返回");
        switch (App.scanner.nextInt()){
            case 1:
                addequip();
                equipPlan();
                break;
            case 2:
                updataequip();
                equipPlan();
                break;
            case 3:
                delEquip();
                equipPlan();
                break;
            case 4:
                showEquip();
                equipPlan();
                break;
            case 0:
                Coachshow();
                break;
            default:
                break;
        }
    }

    private void showEquip() {
        coachService.showEquip();
    }

    private void delEquip() {
        while (true) {
            String name;
            while (true) {
                System.out.println("请输入要删除的装备名");
                name=App.scanner.next();
                Equip equip=coachService.findEquipByName(name);
                if (equip!=null){
                    break;
                }else {
                    System.out.println("不存在该装备，请重新输入");
                }
            }
            boolean b=coachService.delEquip(name);
            System.out.println(b ? "添加成功" : "添加失败");
            System.out.println("是否继续删除(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }

    private void updataequip() {
        while (true) {
            String name;
            while (true) {
                System.out.println("请输入装备名称");
                name=App.scanner.next();
                Equip equip=coachService.findEquipByName(name);
                if (equip!=null){
                    break;
                }else {
                    System.out.println("不存在该装备，请重新输入");
                }
            }
            System.out.println("请输入修改的装备价格");
            double price=App.scanner.nextDouble();
            System.out.println("请输入修改的装备数量");
            int num=App.scanner.nextInt();
            boolean b=coachService.updataequip(name,price,num);
            System.out.println(b ? "修改成功" : "修改失败");
            System.out.println("是否继续修改(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }

    private void addequip() {
        while (true) {
            String name;
            while (true) {
                System.out.println("请输入装备名称");
                name=App.scanner.next();
                Equip equip=coachService.findEquipByName(name);
                if (equip!=null){
                    System.out.println("已有该装备，请重新输入");
                }else {
                    break;
                }
            }
            System.out.println("请输入装备价格");
            double price=App.scanner.nextDouble();
            System.out.println("请输入数量");
            int num=App.scanner.nextInt();
            boolean b=coachService.addEquip(name,price,num);
            System.out.println(b ? "添加成功" : "添加失败");
            System.out.println("是否继续添加 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }

    private void trainingPlan() {
        System.out.println("1.添加训练计划");
        System.out.println("2.修改训练计划");
        System.out.println("3.删除训练计划");
        System.out.println("4.训练计划列表");
        System.out.println("0.返回");
        System.out.println("请输入要操作的编号:");
        switch (App.scanner.nextInt()){
            case 1:
                addPlan();
                break;
            case 2:
                updateTraining();
                break;
            case 3:
                delTraining();
                break;
            case 4:
                showTraining();
                break;
            case 0:
                Coachshow();
                break;
            default:
                break;
        }
    }

    private void delTraining() {
        while (true) {
            int teamId = coach.getTeamId();
            boolean b = coachService.showTraining(teamId);
            if (b){
                System.out.println("请输入要删除的训练计划Id");
                int id = App.scanner.nextInt();
                boolean b1 = coachService.delTraining(id);
                System.out.println(b1 ? "删除成功" : "删除失败");
            }
            System.out.println("是否继续删除(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        trainingPlan();
    }

    private void showTraining() {
        int teamId = coach.getTeamId();
        coachService.showTraining(teamId);
        trainingPlan();
    }

    private void updateTraining() {
        //updateTraining 输入trainingId 判断是否已存在该训练计划 判断该时间是否存在其他训练计划
        while (true) {
            int teamId = coach.getTeamId();
            boolean b = coachService.showTraining(teamId);
            if (b) {
                System.out.println("请输入要修改的训练Id");
                int trainingId=App.scanner.nextInt();
                while (true) {
                    showDetail();
                    System.out.println("请输入修改的详细计划Id");
                    int detailId=App.scanner.nextInt();
                    //输出所有详细计划并检查时间是否重合
                    int time = coachService.findDetailById(detailId).getTime();
                    Detail detailBytime = coachService.getDetailBytime(coach.getTeamId(), time);
                    if (detailBytime==null) {
                        boolean c = coachService.updataTraining(trainingId, detailId);
                        System.out.println(c ? "修改成功" : "修改失败");
                        break;
                    }else {
                        if (time==detailBytime.getTime()){
                            boolean c = coachService.updataTraining(trainingId, detailId);
                            System.out.println(c ? "修改成功" : "修改失败");
                            break;
                        }else {
                            System.out.println("您执教的球队该时间有其他训练计划");
                        }
                    }
                }
            }
            System.out.println("是否继续修改 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        trainingPlan();
    }

    private void addPlan() {
        //addTraining  输入详细计划detailId   添加到自己球队 判断是否已存在该计划 判断该时间是否已存在训练计划
        while (true) {
            int id;
            Detail detail;
            int teamId = 0;
            while (true) {
                while (true) {
                    System.out.println("请输入详细计划序号:");
                    showDetail();
                    id = App.scanner.nextInt();
                    detail = coachService.findDetailById(id);
                    if (detail == null) {
                        System.out.println("不存在该详细计划序号,请重新输入");
                    } else {
                            break;
                    }
                }
                teamId = coach.getTeamId();
                int time = detail.getTime();
                Detail detail1=coachService.getDetailBytime(teamId,time);
                if (detail1!=null){
                    System.out.println("该时间球队有其他训练，请添加其他训练");
                }else {
                    break;
                }
            }
            boolean b=coachService.addTraining(teamId,id);
            System.out.println(b ? "添加成功" : "添加失败");
            System.out.println("是否继续添加 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        trainingPlan();
    }

    private void Playeranalysis() {
        while (true) {
            coachService.Playeranalysis();
            System.out.println("是否继续查询 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Coachshow();
    }

    private void Teamanalysis() {
        //teamScoreByTeamId  from team_score表查询自己球队的所有比赛(主场+客场)记录 输出主场球队名称+得分 客场球队名称+得分
        coachService.Teamanalysis();
        Coachshow();
    }

    private void showGameDeg() {
        System.out.println("1.添加赛程");
        System.out.println("2.修改赛程记录");
        System.out.println("3.删除赛程");
        System.out.println("4.自己球队的赛程");
        System.out.println("5.其他球队赛程");
        System.out.println("0.返回");
        System.out.println("请输入要操作的编号:");
        switch (App.scanner.nextInt()){
            case 1:
                addGames();
                break;
            case 2:
                updataGame();
                break;
            case 3:
                delGame();
                break;
            case 4:
                showMyGame();
                break;
            case 5:
                showAllGame();
                break;
            case 0:
                Coachshow();
                break;
            default:
                break;
        }
    }

    private void addFeedback() {
        int playerId;
        int fanId;
        String description;
        String is;
        while (true){
            while (true) {
                System.out.println("请输入球员编号");
                playerId = App.scanner.nextInt();
                Player players = playerService.findByPlayerId(playerId);
                if (players == null) {
                    System.out.println("该球员不存在");
                } else {
                    break;
                }
            }
                System.out.println("请输入粉丝编号");
                fanId=App.scanner.nextInt();
                System.out.println("请输入球迷评价");
                description=App.scanner.next();
                boolean a=feedbackService.add(playerId,fanId,description);
                System.out.println(a?"评价成功":"评价失败");
                System.out.println("是否继续评价(y/n)");
                is=App.scanner.next();
              if (is.equals("n")){
                System.out.println("评价结束");
                break;
            } else if (is.equals("y")){
            }else {
                break;
            }
        }

    }

    private void playerLikes() {
        String playerName;
        String is;
        while (true){
            while (true) {
                System.out.println("请输入进行点赞的球员名字");
                playerName=App.scanner.next();
                Player player=playerService.findByPlayerName(playerName);
                if (player==null){
                    System.out.println("该球员不存在");
                }else {
                    break;
                }
            }
            boolean a=playerService.Likes(playerName);
            System.out.println(a?"点赞成功":"点赞失败");
            System.out.println("继续点赞(y/n)");
            is=App.scanner.next();
            if (is.equals("n")){
                System.out.println("点赞结束");
                break;
            }else if (is.equals("y")){
            }else {
                break;
            }
        }
    }

    private void showGame() {
        System.out.println("赛程信息");
        List<Game> games=gameService.showGame();
        if (games!=null){
            for (Game game : games) {
                //System.out.println(game.getId()+"\t"+game.getTime()+"\t"+game.getLocation()+"\t"+game.getHomeTeamId()+"\t"+game.getAwayTeamId());
                System.out.println("比赛时间:"+game.getTime());
                System.out.println("比赛地点:"+game.getLocation());
                System.out.println("主场球队:"+coachService.findTeamByTeamId(coachService.findGameById(game.getHomeTeamId()).getHomeTeamId()).getName());
                System.out.println("客场球队:"+coachService.findTeamByTeamId(coachService.findGameById(game.getHomeTeamId()).getAwayTeamId()).getName());
            }
        }else {
            System.out.println("没有比赛");
        }
    }

    private void showAllGame() {
        coachService.showAllGame();
        showGameDeg();
    }

    private void showMyGame() {
        int teamId = coach.getTeamId();
        coachService.showMyGame(teamId);
        showGameDeg();
    }

    private void delGame() {
        while (true) {
            int id;
            while (true) {
                System.out.println("请输入要删除的赛程的id:");
                id=App.scanner.nextInt();
                Game game=coachService.findGameById(id);
                if (game==null){
                    System.out.println("不存在此比赛，请重新输入");
                }else {
                    break;
                }
            }
            boolean c=coachService.delGame(id);
            System.out.println(c ? "删除成功" : "删除失败");
            System.out.println("是否继续删除 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        showGameDeg();
    }

    private void updataGame() {
        while (true) {
            int id;
            while (true) {
                System.out.println("请输入要修改的赛程的id:");
                id=App.scanner.nextInt();
                Game game=coachService.findGameById(id);
                if (game==null){
                    System.out.println("不存在此比赛，请重新输入");
                }else {
                    break;
                }
            }
            Date date= null;
            while (true) {
                    try {
                        System.out.println("请输入要修改的比赛时间:   (年-月-日)");
                        SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd");
                        String str=App.scanner.next();
                        date = time.parse(str);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    if (date==null){
                        System.out.println("输入错误请重新输入时间");
                    }
                List<Game> games;
                games=coachService.findGameByTime(date);
                if (games!=null){
                    for (Game game : games) {
                        if (game.getTime().equals(date)){
                            System.out.println("当前时间有主场球队或客场球队有比赛!请重新输入:");
                            System.out.println("主场:" + game.getHomeTeamId());
                            System.out.println("客场:" + game.getAwayTeamId());
                            System.out.println("时间:" + game.getTime());
                            System.out.println("地点:" + game.getLocation());
                        }
                    }
                }
                break;
            }
            boolean b=coachService.updataGameTime(date,id);
            System.out.println(b ? "修改成功" : "修改失败");
            System.out.println("是否继续修改赛程");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        showGameDeg();
    }

    private void addGames() {
        //addGame  输入 比赛时间 time 比赛地点 location 主场球队id   home_team_id  客场球队id  away_team_id   返回 添加成功+赛程id...等
        //判断主场球队和客场球队当日没有比赛 当天球馆没有比赛
        while (true) {
            System.out.println("请输入主场球队Id：");
            int homeTeamId=App.scanner.nextInt();
            Team team=coachService.findTeamByTeamId(homeTeamId);
            String homeTeamName= team.getName();
            System.out.println("请输入客场球队Id：");
            int awayTeamId=App.scanner.nextInt();
            System.out.println("请输入比赛地点:");
            String loca=App.scanner.next();
            Date date= null;
                while (true) {
                    try {
                        System.out.println("请输入要添加的比赛时间:   (年-月-日)");
                        SimpleDateFormat time=new SimpleDateFormat("yyyy-MM-dd");
                        String str=App.scanner.next();
                        date = time.parse(str);
                    } catch (ParseException e) {
                        e.printStackTrace();
                    }
                    if (date==null){
                        System.out.println("输入错误请重新输入时间");
                    }else {
                        break;
                    }
                }
                List<Game> games;
                games=coachService.findGameByTeamId(homeTeamName);
                if (games!=null){
                    for (Game game : games) {
                    if (game.getTime().equals(date)){
                        //System.out.println("当前时间有主场球队或客场球队有比赛!请重新输入:");
                        System.out.println("主场Id:" + game.getHomeTeamId());
                        System.out.println("客场Id:" + game.getAwayTeamId());
                        System.out.println("时间:" + game.getTime());
                        System.out.println("地点:" + game.getLocation());
                            }
                        }
                    }
                boolean b= coachService.addGame(homeTeamId,awayTeamId,date,loca);
            System.out.println(b ? "添加成功" : "添加失败");
            System.out.println("是否继续添加(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        showGameDeg();
    }

    private void showAllPlayer() {
        coachService.showAllPlayer();
        Coachshow();
    }

    private void showPlayer() {
        while (true) {
            int teamId = coach.getTeamId();
            coachService.showPlayer(teamId);
            System.out.println("是否继续查看球员(y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Coachshow();
    }

    private void delPlayer() {
        //输入playerId   删除player   只能删除自己球队的球员 where coach.id=player.id
        while (true) {
            while (true) {
                System.out.println("请输入球员姓名:");
                String name=App.scanner.next();
                Player player=coachService.findPlayerByName(name);
                if (player==null){
                    System.out.println("不存在球员，请重新输入");
                }else {
                    boolean c= coachService.delPlayerByName(name);
                    System.out.println(c ? "修改成功" : "修改失败");
                    break;
                }
            }
            System.out.println("是否继续删除 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Coachshow();
    }

    private void delPlayer1() {
        //输入playerId   删除player   只能删除自己球队的球员 where coach.id=player.id
        while (true) {
            while (true) {
                System.out.println("请输入球员姓名:");
                String name=App.scanner.next();
                Player player=coachService.findPlayerByName(name);
                if (player==null){
                    System.out.println("不存在球员，请重新输入");
                }else {
                    boolean c= coachService.delPlayerByName(name);
                    System.out.println(c ? "修改成功" : "修改失败");
                    break;
                }
            }
            System.out.println("是否继续删除 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
    }
    private void addPlayers() {
            List<Player> players = new ArrayList<>();
            while (true) {
                System.out.println("请输入添加球员的姓名:");
                String name=App.scanner.next();
                System.out.println("请输入添加球员的年龄:");
                int age=App.scanner.nextInt();
                System.out.println("请输入添加球员的身高:  (cm)");
                int height=App.scanner.nextInt();
                System.out.println("请输入添加球员的体重:   (Kg)");
                int weight=App.scanner.nextInt();
                int position;
                while (true) {
                    System.out.println("请输入添加球员的占位:  (0-5)");
                    position=App.scanner.nextInt();
                    if (position<1 ||position>5){
                        System.out.println("错误，请重新输入");
                    }else {
                        break;
                    }
                }
                System.out.println("请输入添加球员的薪水:");
                int salary=App.scanner.nextInt();
                int teamId = coach.getTeamId();
                Player player = new Player(name, age, height, weight, position, teamId, salary);
                players.add(player);
                System.out.println("继续添加吗(y/n)");
                if (!App.scanner.next().equals("y")){
                    break;
                }
            }
            boolean b=coachService.addPlayers(players);
            System.out.println(b ? "添加成功" : "添加失败");
        Coachshow();
    }
    private void bossAddPlayers() {
        while (true) {
            List<Player> players = new ArrayList<>();
            while (true) {
                System.out.println("请输入添加球员的姓名:");
                String name=App.scanner.next();
                System.out.println("请输入添加球员的年龄:");
                int age=App.scanner.nextInt();
                System.out.println("请输入添加球员的身高:  (cm)");
                int height=App.scanner.nextInt();
                System.out.println("请输入添加球员的体重:   (Kg)");
                int weight=App.scanner.nextInt();
                int position;
                while (true) {
                    System.out.println("请输入添加球员的占位:  (1-5)");
                    position=App.scanner.nextInt();
                    if (position<1 ||position>5){
                        System.out.println("错误，请重新输入");
                    }else {
                        break;
                    }
                }
                System.out.println("请输入添加球员的薪水:");
                int salary=App.scanner.nextInt();
                System.out.println("请输入添加的球队Id");
                int teamId =App.scanner.nextInt();
                Player player = new Player(name, age, height, weight, position, teamId, salary);
                players.add(player);
                System.out.println("继续添加吗(y/n)");
                if (!App.scanner.next().equals("y")){
                    break;
                }
            }
            boolean b=coachService.addPlayers(players);
            System.out.println(b ? "添加成功" : "添加失败");
            System.out.println("是否继续添加");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Bossshow();
    }

    private void Adminshow() {
        System.out.println("1.删除球迷账号");
        System.out.println("2.更改球迷账号信息");
        System.out.println("3.查询球迷账号信息");
        System.out.println("4.更改老板账号信息");
        System.out.println("5.查询老板账号信息");
        System.out.println("6.教练账号管理");
        System.out.println("7.删除教练账号");
        System.out.println("8.查询教练账号信息");
        System.out.println("0.登出");
        switch (App.scanner.nextInt()){
            case 1:
                delFan();
                break;
            case 2:
                updateFan();
                break;
            case 3:
                findFanByFanId();
                break;
            case 4:
                updateBoss();
                break;
            case 5:
                showBoss();
                break;
            case 6:
                updateCoach();
                break;
            case 7:
                delCoach();
                break;
            case 8:
                showCoach();
            break;
            case 0:
                start();
                break;
            default:
                break;
        }
    }

    private void showCoach() {
        while (true) {
            while (true) {
                System.out.println("请输入教练姓名:");
                String name=App.scanner.next();
                //判断教练是否存在
                Coach coach=coachService.findByname(name);
                if (coach==null){
                    System.out.println("教练不存在，请重新输入");
                }else {
                    System.out.println("年龄："+coach.getAge());
                    System.out.println("姓名："+coach.getName());
                    System.out.println("执教经验："+coach.getExperience()+"年");
                    //根据teamId查执教队名
                    Team team= coachService.findTeamByTeamId(coach.getTeamId());
                    if (team!=null) {
                        System.out.println("执教队伍：" + team.getName());
                    }else {
                        System.out.println("自由教练");
                    }
                    System.out.println("工资："+coach.getSalary());
                    break;
                }
            }
            System.out.println("是否继续查询 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }

    private void delCoach() {
        //delCoach 输入coachId 判断是否存在判断是否是自己队的教练 如果是删除
        String name;
        while (true) {
            while (true) {
                System.out.println("请输入教练姓名：");
                name = App.scanner.next();
                Coach coach = coachService.findByname(name);
                if (coach == null) {
                    System.out.println("教练不存在，请重新输入");
                } else {
                    break;
                }
            }
            boolean b = coachService.delCoachByname(name);
            System.out.println(b ? "删除成功" : "删除失败");
            System.out.println("是否继续删除 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }

    private void updateCoach() {
        //updateCoach 输入coachId 判断教练是否存在 判断是否是自己队的教练 如果是1username 2.password 3team_id 4salary
        String name;
        while (true) {
            while (true) {
                System.out.println("请输入教练姓名:");
                name=App.scanner.next();
                //判断教练是否存在
                Coach coach=coachService.findByname(name);
                if (coach==null){
                    System.out.println("教练不存在，请重新输入");
                }else {
                    break;
                }
            }
            System.out.println("请输入要修改的内容:");
            System.out.println("1.username ");
            System.out.println("2.password ");
            System.out.println("3.team_id");
            //System.out.println("4.salary");
            switch (App.scanner.nextInt()){
                case 1:
                    System.out.println("请输入修改后的username：");
                    String newUsername=App.scanner.next();
                    boolean b=coachService.updateUsername(newUsername,name);
                    System.out.println(b?"修改成功":"修改失败");
                    break;
                case 2:
                    System.out.println("请输入修改后的password:");
                    String newPassword=App.scanner.next();
                    boolean c=coachService.updatePassword(newPassword,name);
                    System.out.println(c?"修改成功":"修改失败");
                    break;
                case 3:
                    System.out.println("请输入修改后的team_id:");
                    String newTeamId=App.scanner.next();
                    boolean d=coachService.updateTeamId(newTeamId,name);
                    System.out.println(d?"修改成功":"修改失败");
                    break;
                case 4:
                    System.out.println("请输入修改后的salary:");
                    String newSalary=App.scanner.next();
                    boolean e=coachService.updateSalary(newSalary,name);
                    System.out.println(e?"修改成功":"修改失败");
                    break;
                default:
                    break;
            }
            System.out.println("是否继续修改 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }

    private void showBoss() {
        //showBoss  输入bossId 判断是否存在如存在 sout  username password name phone
        while (true) {
            while (true) {
                System.out.println("请输入BossId:");
                int bossId=App.scanner.nextInt();
                Boss boss=bossService.findBossByBossId(bossId);
                if (boss==null){
                    System.out.println("老板不存在,请重新输入老板Id");
                }else {
                    System.out.println("用户名:"+boss.getUsername());
                    System.out.println("密码:"+ boss.getPassword());
                    System.out.println("姓名:"+boss.getName());
                    System.out.println("电话:"+boss.getPhone());
                    break;
                }
            }
            System.out.println("是否继续查询 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }

    private void updateBoss() {
        //updateBoss  输入username password 判断是否正确 判断是否存在 要更改的信息1. username 2.password 3.name 4.phone
        int bossId;
        while (true) {
            while (true) {
                System.out.println("请输入BossId:");
                bossId=App.scanner.nextInt();
                Boss boss=bossService.findBossByBossId(bossId);
                if (boss==null){
                    System.out.println("老板不存在,请重新输入老板Id");
                }else {
                    break;
                }
            }
            System.out.println("1.username");
            System.out.println("2.password");
            System.out.println("3.name ");
            System.out.println("4.phone");
            System.out.println("请输入你要修改的内容：");
            switch (App.scanner.nextInt()){
                case 1:
                    System.out.println("请输入修改后的username:");
                    String newUsername=App.scanner.next();
                    boolean b=bossService.updateUsername(newUsername,bossId);
                    System.out.println(b?"修改成功":"修改失败");
                    break;
                case 2:
                    System.out.println("请输入修改后的password:");
                    String newPassword=App.scanner.next();
                    boolean c=bossService.updatePassword(newPassword,bossId);
                    System.out.println(c?"修改成功":"修改失败");
                    break;
                case 3:
                    System.out.println("请输入修改后的name:");
                    String newName=App.scanner.next();
                    boolean d=bossService.updateName(newName,bossId);
                    System.out.println(d?"修改成功":"修改失败");
                    break;
                case 4:
                    System.out.println("请输入修改后的phone:");
                    String newPhone=App.scanner.next();
                    boolean e=bossService.updatePhone(newPhone,bossId);
                    System.out.println(e?"修改成功":"修改失败");
                    break;
                default:
                    break;
            }
            System.out.println("是否继续修改 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }
    private void findBossByBossId() {
        //findBossByBossId  输入bossId 判断是否存在如存在 sout  username password name phone
        while (true) {
            System.out.println("请输入BossId:");
            int bossId=App.scanner.nextInt();
            Boss boss=bossService.findBossByBossId(bossId);
            if (boss==null){
                System.out.println("老板不存在,请重新输入老板Id");
            }else {
                System.out.println("老板姓名:"+boss.getName());
                System.out.println("老板username:" + boss.getUsername());
                System.out.println("老板password:" + boss.getPassword());
                System.out.println("老板phone:" + boss.getPhone());
                break;
            }
        }
    }
    private void findFanByFanId() {
        //findFanByFanId 判断是否存在 如存在输出球迷name username  password
        while (true) {
            int fanId;
            while (true) {
                System.out.println("请输入粉丝Id");
                fanId = App.scanner.nextInt();
                Fan fan = fanService.findByFanId(fanId);
                if (fan == null) {
                    System.out.println("粉丝不存在,请重新输入粉丝Id");
                } else {
                    System.out.println("粉丝姓名:"+fan.getName());
                    System.out.println("粉丝username:" + fan.getUsername());
                    System.out.println("粉丝password:" + fan.getPassword());
                    System.out.println("粉丝phone:" + fan.getPhone());
                    break;
                }
            }
            System.out.println("是否继续查询 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }
    private void updateFan() {
        //输入fanId  判断是否存在 如存在 1改username 2改password 3改name 4改phone
        while (true) {
            int fanId;
            while (true) {
                System.out.println("请输入粉丝Id");
                fanId = App.scanner.nextInt();
                Fan fan = fanService.findByFanId(fanId);
                if (fan == null) {
                    System.out.println("粉丝不存在,请重新输入粉丝Id");
                } else {
                    break;
                }
            }
            //存在
            System.out.println("1.username");
            System.out.println("2.password");
            System.out.println("3.name");
            System.out.println("4.phone");
            System.out.println("请输入要修改的粉丝信息");
            switch (App.scanner.nextInt()){
                case 1:
                    System.out.println("请输入修改后的username:");
                    String newUsername=App.scanner.next();
                    boolean b=fanService.updateUsername(newUsername,fanId);
                    System.out.println(b?"修改成功":"修改失败");
                    break;
                case 2:
                    System.out.println("请输入修改后的password");
                    String newPassword=App.scanner.next();
                    boolean c=fanService.updatePassowrd(newPassword,fanId);
                    System.out.println(c?"修改成功":"修改失败");
                    break;
                case 3:
                    System.out.println("请输入修改后的name");
                    String newName=App.scanner.next();
                    boolean d=fanService.updateName(newName,fanId);
                    System.out.println(d?"修改成功":"修改失败");
                    break;
                case 4:
                    System.out.println("请输入修改后的phone");
                    String newPhone=App.scanner.next();
                    boolean e=fanService.updatePhone(newPhone,fanId);
                    System.out.println(e?"修改成功":"修改失败");
                    break;
                default:
                    break;
            }
            System.out.println("是否继续修改 (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }
    private void delFan() {
        //输入fanId 判断是否存在 存在删除
        while (true) {
            int fanId;
            while (true) {
                System.out.println("请输入粉丝Id");
                fanId = App.scanner.nextInt();
                Fan fan = fanService.findByFanId(fanId);
                if (fan == null) {
                    System.out.println("粉丝不存在,请重新输入粉丝Id");
                } else {
                    break;
                }
            }
            //存在删除
            boolean b = fanService.del(fanId);
            if (b){
                System.out.println("删除成功");
            }else {
                System.out.println("删除失败");
            }
            System.out.println("是否继续删除? (y/n)");
            if (App.scanner.next().equals("n")){
                break;
            }
        }
        Adminshow();
    }
    //老板区
    private void Bossshow(){
        System.out.println("1.球队管理");
        System.out.println("2.球员管理");
        System.out.println("3.教练分配");
        System.out.println("4.查看工资列表");
        System.out.println("5.登出");
        switch (App.scanner.nextInt()){
            case 1:
                System.out.println("请输入要执行的操作序号");
                System.out.println("1.增加球队");
                System.out.println("2.删除球队");
                System.out.println("3.修改球队");
                System.out.println("4.查询球队");
                System.out.println("5.返回");
                switch (App.scanner.nextInt()){
                    case 1:
                        try {
                            addTeam();
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                        Bossshow();
                        break;
                    case 2:
                        delTeam();
                        Bossshow();
                        break;
                    case 3:
                        updateTeam();
                        Bossshow();
                        break;
                    case 4:
                        showTeam();
                        Bossshow();
                        break;
                    case 5:
                        Bossshow();
                        break;
                    default:
                        break;
                }
                break;
            case 2:
                System.out.println("请输入要执行的操作序号");
                System.out.println("1.添加球员");
                System.out.println("2.删除球员");
                System.out.println("3.修改球员");
                System.out.println("4.查询球员");
                System.out.println("5.返回");
                switch (App.scanner.nextInt()){
                    case 1:
                        bossAddPlayers();
                        Bossshow();
                        break;
                    case 2:
                        delPlayer1();
                        Bossshow();
                        break;
                    case 3:
                        updatePlayer();
                        Bossshow();
                        break;
                    case 4:
                        showAllPlayer();
                        Bossshow();
                        break;
                    case 5:
                        Bossshow();
                        break;
                    default:
                        break;
                }
                break;
            case 3:
                System.out.println("请输入要执行的操作序号");
                System.out.println("1.解雇教练");
                System.out.println("2.修改教练信息");
                System.out.println("3.查看教练列表");
                System.out.println("4.返回");
                switch (App.scanner.nextInt()){
                    case 1:
                        dismissCoach();
                        Bossshow();
                        break;
                    case 2:
                        updateCoach1();
                        Bossshow();
                        break;
                    case 3:
                        showCoach1();
                        Bossshow();
                        break;
                    case 4:
                        Bossshow();
                        break;
                    default:
                        break;
                }
                break;
            case 4:
                showSalary();
                Bossshow();
                break;
            case 5:
                start();
                break;
            default:
                break;
        }
    }
    //增加球队
    private void addTeam() throws ParseException {
        int teamId;
        String teamName;
        Date teamCreatDate = null;
        String is;
        while (true) {
            System.out.println("请输入球队名字");
            teamName=App.scanner.next();
            Team team=teamService.findByTeamName(teamName);
            if (team!=null){
                System.out.println("该球队已经存在");
            }else {
                break;
            }
        }
        while (true) {
            System.out.println("请输入球队编号");
            teamId=App.scanner.nextInt();
            System.out.println("请输入球队创建日期");
            String s=App.scanner.next();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = simpleDateFormat.parse(s);

            Team team=new Team(teamId,teamName,date);
            boolean a=teamService.add(team,boss.getId());
            System.out.println(a?"添加成功":"添加失败");
            //是否继续添加
            System.out.println("继续添加吗？(y/n)");
            is=App.scanner.next();
            if (is.equals("n")){
                System.out.println("添加结束");
                break;
            }else if (is.equals("y")){
                while (true) {
                    System.out.println("请输入球队名字");
                    teamName=App.scanner.next();
                    team=teamService.findByTeamName(teamName);
                    if (team!=null){
                        System.out.println("该球队已经存在");
                    }else {
                        break;
                    }
                }
            }else {
                break;
            }
        }
    }
    //删除球队
    private void delTeam() {
        String teamName;
        String is;
        while (true){
            while (true) {
                System.out.println("请输入球队名字");
                teamName=App.scanner.next();
                Team team=teamService.findByTeamName(teamName);
                if (team==null){
                    System.out.println("该球队不存在");
                }else {
                    //判断是否为自己的球队
                    BossTeam bossTeam=teamService.findByTeamId(team.getId());
                    if (bossTeam!=null) {
                        if (bossTeam.getBossId() != boss.getId()) {
                            System.out.println("这不是您的球队，不能删除,请重新输入");
                        } else {
                            break;
                        }
                    }
                }
            }
            Team team =new Team(teamName);
            boolean a=teamService.del(team);
            System.out.println(a?"删除成功":"删除失败");
            System.out.println("继续删除吗？(y/n)");
            is=App.scanner.next();
            if (is.equals("n")){
                System.out.println("删除结束");
                break;
            }else if (is.equals("y")){
            }else {
                break;
            }
        }
    }
    //修改球队
    private void updateTeam() {
        String teamName;
        String teamName1;
        int teamId;
        String is;
        while (true){
            Team team;
            while (true) {
                while (true) {
                    System.out.println("请输入修改的球队的名字");
                    teamName = App.scanner.next();
                    team = teamService.findByTeamName(teamName);
                    if (team == null) {
                        System.out.println("该球队不存在");
                    } else {
                        break;
                    }
                }
                //判断是否为自己的球队
                BossTeam bossTeam=teamService.findByTeamId(team.getId());
                if (bossTeam!=null) {
                    if (bossTeam.getBossId() != boss.getId()) {
                        System.out.println("这不是您的球队，不能修改,请重新输入");
                    } else {
                        break;
                    }
                }
            }
            System.out.println("请输入"+teamName+"修改后的名字");
            teamName1=App.scanner.next();
            System.out.println("请输入"+teamName+"修改后球队编号");
            teamId=App.scanner.nextInt();
            System.out.println("请输入"+teamName+"修改后球队创建日期");
            String s=App.scanner.next();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
            Date date = null;
            try {
                date = simpleDateFormat.parse(s);
            } catch (ParseException e) {
                e.printStackTrace();
            }
           /* Team team=new Team(teamId,teamName1,date,teamName);*/
            boolean a=teamService.update(teamId,teamName1,date,teamName);
            System.out.println(a?"修改成功":"修改失败");
            System.out.println("继续修改吗？(y/n)");
            is=App.scanner.next();
            if (is.equals("n")){
                System.out.println("修改结束");
                break;
            }else if (is.equals("y")){
            }else {
                break;
            }
        }

    }
    //查询球队信息
    private void showTeam() {
        System.out.println("球队列表");
        List<Team> teams =teamService.showAll();
        if (teams!=null){
            for (Team team : teams) {
                //System.out.println(team.getId()+"\t"+team.getName()+"\t"+team.getEstablishedDate());
                System.out.println("球队Id:"+team.getId());
                System.out.println("球队名字:"+ team.getName());
                System.out.println("建队日期:" + team.getEstablishedDate());
            }
        }else {
            System.out.println("没有球队，请添加球队");
        }
    }
    //修改球员信息
    private void updatePlayer() {
        String playerName;
        int playerid;
        String playerName1;
        int playerAge;
        int playerHeight ;
        int playerWeight;
        int position;
        int team_id;
        int playerSalary;
        int likes;
        String is;
        while (true){
            Player player;
            while (true) {
                    System.out.println("请输入进行修改的球员名字");
                    playerName=App.scanner.next();
                    player=playerService.findByPlayerName(playerName);
                    if (player==null){
                        System.out.println("该球员不存在");
                    }else {
                        break;
                    }
                }
                BossTeam bossTeam=teamService.findByTeamId(player.getTeamId());
                if (bossTeam!=null){
                if (boss.getId()!=bossTeam.getBossId()){
                    System.out.println("这不是您球队的球员，不能修改，请重新输入");
                }
            }
            System.out.println("请输入修改后球员的名字");
            playerName1=App.scanner.next();
            System.out.println("请输入修改后球员编号");
            playerid=App.scanner.nextInt();
            System.out.println("请输入修改后球员的年龄");
            playerAge=App.scanner.nextInt();
            System.out.println("请输入修改后球员的身高");
            playerHeight=App.scanner.nextInt();
            System.out.println("请输入修改后球员的体重");
            playerWeight=App.scanner.nextInt();
            System.out.println("请输入修改后球员的球场位置");
            position=App.scanner.nextInt();
            System.out.println("请输入修改后球员的球队编号");
            team_id=App.scanner.nextInt();
            System.out.println("请输入修改后球员的工资");
            playerSalary=App.scanner.nextInt();
            System.out.println("请输入修改后球员的点赞数");
            likes=App.scanner.nextInt();
            boolean a=playerService.update(playerid,playerName1,playerAge,playerHeight,playerWeight,position,team_id,playerSalary,likes,playerName);
            System.out.println(a?"修改成功":"修改失败");
            System.out.println("继续修改吗？(y/n)");
            is=App.scanner.next();
            if (is.equals("n")){
                System.out.println("修改结束");
                break;
            }else if (is.equals("y")){
            }else {
                break;
            }
        }
    }
    //解雇教练
    private void dismissCoach() {
        String CoachName;
        String is;
        while (true){
            Coach coach;
                while (true) {
                    System.out.println("请输入解雇教练的名字");
                    CoachName = App.scanner.next();
                    coach = coachService.findByCoachName(CoachName);
                    if (coach == null) {
                        System.out.println("该教练不存在");
                    } else {
                        break;
                    }
                }
            boolean a=coachService.dismiss(CoachName);
            System.out.println(a?"解雇成功":"解雇失败");
            System.out.println("继续修改吗？(y/n)");
            is=App.scanner.next();
            if (is.equals("n")){
                System.out.println("解雇结束");
                break;
            }else if (is.equals("y")){
            }else {
                break;
            }
        }
    }
    //查询教练列表
    private  void showCoach1(){
        System.out.println("教练列表");
        List<Coach> coaches=coachService.showCoach();
        if (coaches!=null){
            for (Coach coach : coaches) {
                //System.out.println(coach.getId()+"\t"+coach.getUsername()+"\t"+"\t"+coach.getPassword()+"\t"+coach.getName()+"\t"+ coach.getAge()+"\t"+ coach.getExperience()+"\t"+ coach.getTeamId()+"\t"+ coach.getSalary());
                System.out.println("教练Id:"+coach.getId());
                System.out.println("教练姓名:" + coach.getName());
                System.out.println("教练年龄:"+coach.getAge());
                System.out.println("执教经验:" + coach.getExperience() + "年");
                System.out.println("执教队伍:" + coachService.findTeamByTeamId(coach.getTeamId()));
                System.out.println("薪资:" + coach.getSalary()+"元");
            }
        }else {
            System.out.println("您没有教练");
        }
    }
    //修改教练信息
    private void updateCoach1(){
        String CoachName;
        String CoachName1;
         int CoachAge;
         int CoachExperience;
         int CoachTeamId;
         int CoachSalary;
         int CoachId;
         String CoachUserName;
         String CoachPassWord;
         String is;
         while (true){
                 while (true) {
                     System.out.println("请输入进行修改信息的教练名字");
                     CoachName = App.scanner.next();
                     Coach coach = coachService.findByCoachName(CoachName);
                     if (coach == null) {
                         System.out.println("该教练不存在");
                     } else {
                         break;
                     }
                 }
                 BossTeam bossTeam = teamService.findByTeamId(coach.getTeamId());
                 if (bossTeam != null) {
                     if (bossTeam.getBossId() != boss.getId()) {
                         System.out.println("这不是您球队的教练,不能修改,请重新输入");
                     }
                 }
             System.out.println("将教练"+CoachName+"修改为");
             CoachName1=App.scanner.next();
             System.out.println("请输入修改后的教练年龄");
             CoachAge=App.scanner.nextInt();
             System.out.println("请输入修改后的教练执教年数");
             CoachExperience=App.scanner.nextInt();
             System.out.println("请输入修改后的执教球队的编号");
             CoachTeamId=App.scanner.nextInt();
             System.out.println("请输入修改后的教练工资");
             CoachSalary=App.scanner.nextInt();
             System.out.println("请输入修改后的教练编号");
             CoachId=App.scanner.nextInt();
             System.out.println("请输入修改后的教练用户名");
             CoachUserName=App.scanner.next();
             System.out.println("请输入修改后的教练用户密码");
             CoachPassWord=App.scanner.next();
             boolean a=coachService.update(CoachId,CoachUserName,CoachPassWord,CoachName1,CoachAge,CoachExperience,CoachTeamId,CoachSalary,CoachName);
             System.out.println(a?"修改成功":"修改失败");
             System.out.println("是否继续修改(y/n)");
             is=App.scanner.next();
             if (is.equals("n")){
                 System.out.println("修改结束");
                 break;}else if (is.equals("y")){
             }else {
                 break;
             }
         }

    }
    //查看工资列表
    private void showSalary() {
        System.out.println("球员薪资");
        List<Player> players=playerService.showPlayerSalary();
        if (players!=null){
            //System.out.println("姓名      工资");
            for (Player player : players) {
                //System.out.println(player.getName()+"\t    "+player.getSalary());
                System.out.println("球员姓名:"+player.getName());
                System.out.println("薪水:" + player.getSalary());
            }
        }else {
            System.out.println("您没有球员");
        }
        System.out.println("教练薪资");
        List<Coach> coaches=coachService.showCoachSalary();
        if (coaches!=null){
            //System.out.println("姓名      工资");
            for (Coach coach : coaches) {
                System.out.println("教练姓名:"+coach.getName());
                System.out.println("教练工资:"+coach.getSalary());
            }
        }else {
            System.out.println("您没有教练");
        }
    }
    private Person log() {
        while (true) {
            System.out.println("1.我是admin");
            System.out.println("2.我是boss");
            System.out.println("3.我是coach");
            System.out.println("4.我是fan");
            System.out.println("0.退出");
            System.out.println("请输入你的身份:");
            int data=App.scanner.nextInt();
            if (data==0){
                System.exit(0);
            }
            System.out.println("请输入账号:");
            String username= App.scanner.next();
            System.out.println("请输入密码:");
            String password=App.scanner.next();
            Person person = null;
            switch (data){
                case 1:
                    person= adminService.log(username,password);
                    break;
                case 2:
                    person=bossService.log(username,password);
                    boss=bossService.findBossByusername(username);
                    break;
                case 3:
                    person= coachService.log(username,password);
                    coach=coachService.findByUsername(username);
                    break;
                case 4:
                    person= fanService.log(username,password);
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
                    break;
            }
            if (person==null){
                System.out.println("账号不存在，请重新登录");
            }else {
                System.out.println("登陆成功");
                if (person instanceof Admin){
                    System.out.println("欢迎管理员");
                }if (person instanceof Boss){
                    System.out.println("欢迎老板");
                }if (person instanceof Coach){
                    System.out.println("欢迎教练");
                }if (person instanceof Fan){
                    System.out.println("欢迎粉丝");
                }
                return person;
            }
        }
    }
}
